﻿using UtilZ.Dotnet.Ex.Communication.Base;
using UtilZ.Dotnet.Ex.Communication.Net.Udp;

namespace UtilZ.Dotnet.Ex.Communication.Net.BMQ
{
    /// <summary>
    /// UDP分包器-收到一个包就直接输出
    /// </summary>
    public class BMQUDPUnpacker : UnpackerAbs
    {
        private readonly BMQDataOutputArgs _args = new BMQDataOutputArgs();
        /// <summary>
        /// 构造函数
        /// </summary>
        public BMQUDPUnpacker()
        {

        }

        /// <summary>
        /// 对数据进行拆包
        /// </summary>
        /// <param name="unpackerPara">分包参数</param>
        /// <returns>拆包成功的数据长度</returns>
        protected override int PrimitiveUnPackge(IUnpackerPara unpackerPara)
        {
            var np = (NetUdpUnpackerPara)unpackerPara;
            if (np.DataLength <= 0)
            {
                return np.DataLength;
            }

            this._args.Update(unpackerPara.LinkInfo, np.Buffer, np.Offset, np.DataLength);
            base.OnRaiseOnReceivedData(np.Client, this._args);
            return np.DataLength;
        }
    }
}
